package com.hualan.sfzy.service.counselor.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.Appointment;
import com.hualan.sfzy.entity.CounselorCharging;
import com.hualan.sfzy.entity.CounselorComment;
import com.hualan.sfzy.mapper.AppointmentMapper;
import com.hualan.sfzy.mapper.counselor.CounselorChargingMapper;
import com.hualan.sfzy.service.counselor.AppointmentService;
import com.hualan.sfzy.service.counselor.CounselorChargingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AppointmentServiceImpl implements AppointmentService {
    @Autowired
    private AppointmentMapper mapper;

    @Override
    public int add(Appointment entity) {
        return mapper.insert( entity);
    }

    @Override
    public int edit(Appointment entity) {
        return mapper.update( entity);
    }

    @Override
    public int remove(Integer id) {
        return mapper.delete( id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return mapper.deleteBatch( ids);
    }

    @Override
    public List<Appointment> find() {
        return mapper.select( null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Appointment entity) {

        // 开启分页
        PageHelper.startPage(pageNum, pageSize);
        List<Appointment> list = mapper.select(entity); // 当前页数据
        PageInfo<Appointment> pageInfo = new PageInfo<>(list); // 分页信息对象
        Map<String, Object> map = new HashMap<>();
        // map存储当前页数据、总页数、总记录数
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }

    @Override
    public Appointment findById(Integer id) {
        return mapper.selectById( id);
    }
}
